home *** CD-ROM | disk | FTP | other *** search
- /***************
-
- ShapeWalker Test application.
-
- This application converts a piece of text to
- a path and then uses the shape walker library
- to read the points from the result. The callback
- routines are used to print out the points in the
- segments.
-
- This demonstrates how the library is used for reading
- gx shapes.
-
- **************/
-
- #include <stdio.h>
- #include "PathWalking.h"
-
-
- /***
- The following structure is used
- to maintain a state during walking
- a shape. It saves the current point
- as well as the first point in a contour
- ***/
- typedef struct {
-
- gxPoint currentPoint; // current pen
- gxPoint firstPoint; // first point in countour.
-
- } TestWalkRec;
-
- #define fix2float(x) ( (double)x / 65536.0)
-
-
- Boolean TestMoveto(gxPoint *p, TestWalkRec* pWalk);
- Boolean TestMoveto(gxPoint *p, TestWalkRec* pWalk)
- {
- pWalk->currentPoint.x = p->x;
- pWalk->currentPoint.y = p->y;
-
- pWalk->firstPoint.x = p->x;
- pWalk->firstPoint.y = p->y;
-
- printf("Begin new contour: %f, %f\n", fix2float(p->x), fix2float(p->y));
-
- return(false);
- }
-
-
-
- Boolean TestLineto(gxPoint *p, TestWalkRec* pWalk);
- Boolean TestLineto(gxPoint *p, TestWalkRec* pWalk)
- {
- printf("Line from %f, %f to %f, %f\n", fix2float(pWalk->currentPoint.x),
- fix2float(pWalk->currentPoint.y),
- fix2float(p->x), fix2float(p->y));
- pWalk->currentPoint.x = p->x;
- pWalk->currentPoint.y = p->y;
-
- return(false);
- }
-
-
-
- Boolean TestCurveTo(gxPoint p[3], TestWalkRec* pWalk);
- Boolean TestCurveTo(gxPoint p[3], TestWalkRec* pWalk)
- {
- printf("Curve from %f, %f through %f, %f, to %f, %f\n",
- fix2float(p[0].x), fix2float(p[0].y),
- fix2float(p[1].x), fix2float(p[1].y),
- fix2float(p[2].x), fix2float(p[2].y));
-
- pWalk->currentPoint.x = p[2].x;
- pWalk->currentPoint.y = p[2].y;
-
- return(false);
- }
-
-
-
- Boolean TestClosePath( TestWalkRec* pWalk);
- Boolean TestClosePath( TestWalkRec* pWalk)
- {
- printf("Closing the contour\n\n");
-
- pWalk->currentPoint.x = pWalk->firstPoint.x;
- pWalk->currentPoint.y = pWalk->firstPoint.y;
-
- return(false);
- }
-
- void main() {
-
- gxShape theShape;
- gxPoint location = {ff(100), ff(100)};
- TestWalkRec walker;
- Boolean result;
-
- theShape = GXNewText(5, (unsigned char*)"Hello", &location);
- GXSetShapeTextSize(theShape, ff(50));
- GXSetShapeType(theShape, gxPathType);
- GXSetShapeFill(theShape, gxClosedFrameFill);
-
- result = ShapeWalker( theShape, (TpwMovetoProc)TestMoveto, (TpwLinetoProc)TestLineto,
- (TpwCurvetoProc)TestCurveTo, (TpwClosepathProc)TestClosePath, (void *)&walker);
-
- GXDisposeShape(theShape);
-
- }